package com.ecar.api.service.order.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ecar.api.service.order.OrderLostService;
import com.ecar.api.support.util.UuidUtils;
import com.ecar.common.dto.DataBean;
import com.ecar.common.util.JSONUtil;
import com.ecar.core.order.dao.OrderLostMapper;
import com.ecar.core.order.entity.OrderLost;

import net.sf.json.JSONObject;

@Service
@Transactional
public class OrderLostServiceImpl implements OrderLostService {
	
	@Autowired
	OrderLostMapper orderLostMapper;
	
	/**
	 * @author fire
	 * 失物申请
	 */
	@Override
	public DataBean insertLost(JSONObject fields) {
		OrderLost orderLost = JSONUtil.deserialize(fields, OrderLost.class);
		orderLost.setId(UuidUtils.getUUID());
		//默认为1，遗失状态
		orderLost.setStatus(1);
		orderLost.setCreateTime(new Date());
		int pk=orderLostMapper.insert(orderLost);
		if(pk<=0){
			return new DataBean(500,new JSONObject(),"申请失败");
		}
		return new DataBean(200,new JSONObject(),"申请成功");
	}
	
	@Override
	public int deleteByPrimaryKey(String id) {
		// TODO Auto-generated method stub
		return orderLostMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(OrderLost record) {
		// TODO Auto-generated method stub
		return orderLostMapper.insert(record);
	}

	@Override
	public int insertSelective(OrderLost record) {
		// TODO Auto-generated method stub
		return orderLostMapper.insertSelective(record);
	}

	@Override
	public OrderLost selectByPrimaryKey(String id) {
		// TODO Auto-generated method stub
		return orderLostMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(OrderLost record) {
		// TODO Auto-generated method stub
		return orderLostMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(OrderLost record) {
		// TODO Auto-generated method stub
		return orderLostMapper.updateByPrimaryKey(record);
	}

}
